home *** CD-ROM | disk | FTP | other *** search
- /*
- WASTE Demo Project:
- Demo Header
-
- Copyright © 1993-1995 Marco Piovanelli
- All Rights Reserved
-
- C port by John C. Daub
- */
-
- /*
- Due to differences between Pascal and C, this file (nothing like it originally existed
- in the original Pascal code) was neccessary to create. In it contains various macros,
- constants, type and class declarations, function prototypes, etc.. From the original
- code, some of this material would be spread amongst the source files, but a good
- majority of this file comes from the WEDemoIntf.p file (the declarations, constants, etc).
- There still is a WEDemoIntf.c file in the project tho since the .p file had a few
- utility functions declared and defined in it.
- */
-
- #ifndef __WEDEMOAPP__
- #define __WEDEMOAPP__
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
- #ifndef __CONTROLS__
- #include <Controls.h>
- #endif
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
- #ifndef _WASTE_
- #include "WASTE.h"
- #endif
- #ifndef _LIMITS
- #include "limits.h"
- #endif
-
-
- /*
- * Some utility macros.
- */
-
-
-
- // "Originally," these are things built into the Pascal language
- // but since C doesn't have anything like them, and in an attempt to keep the code readable
- // and similar to the original Pascal source, these #define macros work nice.
-
-
- #define BTST( FLAGS, BIT ) (((FLAGS) & (1L << (BIT))) ? 1 : 0)
- #define BSET( FLAGS, BIT ) ((FLAGS) |= (1L << (BIT)))
- #define BCLR( FLAGS, BIT ) ((FLAGS) &= (~(1L << (BIT))))
-
- #define ABS(A) ((A) > 0 ? (A) : -(A))
-
- #define BSL(A, B) (((long)A) << (B))
- #define BSR(A, B) (((long)A) >> (B))
- #define BOR(A, B) ( A | B )
- #define BAND(A, B) ( A & B )
-
- #ifndef HiWrd
- #define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF )
- #endif
- #ifndef LoWrd
- #define LoWrd(aLong) ((aLong) & 0xFFFF )
- #endif
-
- // WASTE Demo signature
-
- #define kAppSignature 'OEDE'
-
- // resource types, clipboard types, and file types
-
- #define kTypeDeskAccessory 'DRVR'
- #define kTypeFont 'FONT'
- #define kTypePicture 'PICT'
- #define kTypeSound 'snd '
- #define kTypeSoup 'SOUP'
- #define kTypeStyles 'styl'
- #define kTypeText 'TEXT'
- #define kTypeTextReadOnly 'ttro'
-
- // virtual key codes for navigation keys found on extended keyboards
-
- #define keyPgUp 0x74
- #define keyPgDn 0x79
- #define keyHome 0x73
- #define keyEnd 0x77
-
- // virtual key codes generated by some function keys
-
- #define keyF1 0x7A
- #define keyF2 0x78
- #define keyF3 0x63
- #define keyF4 0x76
-
- // possible values for HandleOpenDocument refCon parameter
-
- enum {
- kDoOpen = 0,
- kDoPrint = 1
- };
-
- // other commonly used constants
-
- #define kBarWidth 16 // width of a scroll bar
- #define kTitleHeight 20 // usual height of a window title bar
- #define kTextMargin 3 // indent of text rect from a window port rect
- #define kScrollDelta 11 // pixels to scroll when the scroll bar arrow is clicked
-
- #define kMinSystemVersion 0x0700 // system 7
- #define kScrapThreshold 4 * 1024
-
- // enumeration types used for closing a window and/or quitting the application
-
- typedef enum {closingWindow, closingApplication} ClosingOption;
- typedef enum {savingYes, savingNo, savingAsk} SavingOption;
-
-
- /*
- * Resource ID numbers
- */
-
- // menu IDs
-
- enum {
- kMenuApple = 1,
- kMenuFile,
- kMenuEdit,
- kMenuFont,
- kMenuSize,
- kMenuStyle,
- kMenuColor,
- kMenuFeatures,
- kMenuAlignment
- };
-
- // Apple Menu items
-
- enum {
- kItemAbout = 1
- };
-
- // File menu items
-
- enum {
- kItemNew = 1,
- kItemOpen = 2,
- kItemClose = 4,
- kItemSave = 5,
- kItemSaveAs = 6,
- kItemQuit = 8
- };
-
- // Edit menu items
-
- enum {
- kItemUndo = 1,
- kItemCut = 3,
- kItemCopy = 4,
- kItemPaste = 5,
- kItemClear = 6,
- kItemSelectAll = 7
- };
-
- // Size menu items
-
- enum {
- kItemLastSize = 6,
- kItemSmaller = 8,
- kItemLarger = 9
- };
-
- // Style menu items
-
- enum {
- kItemPlainText = 1,
- kItemBold,
- kItemItalic,
- kItemUnderline,
- kItemOutline,
- kItemShadow,
- kItemCondensed,
- kItemExtended
- };
-
- // Color menu items
-
- enum {
- kItemBlack = 1,
- kItemRed,
- kItemGreen,
- kItemBlue,
- kItemCyan,
- kItemMagenta,
- kItemYellow
- };
-
- // Alignment menu items
-
- enum {
- kItemAlignDefault = 1,
- kItemAlignLeft = 3,
- kItemCenter,
- kItemAlignRight,
- kItemJustify
- };
-
- // Features menu items
-
- enum {
- kItemAlignment = 1,
- kItemTabHooks,
- kItemAutoScroll = 4,
- kItemOutlineHilite,
- kItemReadOnly,
- kItemIntCutAndPaste,
- kItemDragAndDrop,
- kItemOffscreenDrawing
- };
-
-
- // Alert & dialog template resource IDs
-
- enum {
- kAlertNeedSys7 = 128,
- kAlertGenError = 130,
- kAlertSaveChanges = 131,
- kDialogAboutBox = 256
- };
-
- // String list resource IDs
-
- enum {
- kUndoStringsID = 128,
- kClosingQuittingStringsID
- };
-
- // miscellaneous resource IDs
-
- enum {
- kMenuBarID = 128,
- kWindowTemplateID = 128,
- kScrollBarTemplateID = 128,
- kPromptStringID = 128
- };
-
- /*
- With the declaration of the ScrollBarPair type, there was some Pascal-specific things
- that Marco did, so I took a little bit of liberty. I could more easily consolodate
- things, but I'm trying to maintain as much similarity to the original code as possible
- (i.e. just axe the ScrollBarPair struct and put it all in the DocumentRec struct)
- */
-
-
- // a ScrollBarPair is just a pair of control handles.
-
- struct ScrollBarPair
- {
- ControlRef v;
- ControlRef h;
- };
-
- typedef struct ScrollBarPair ScrollBarPair, *ScrollBarPairPtr, **ScrollBarPairHandle;
-
- // a DocumentRecord is a structure associated with each window
- // a handle to this structure is kept in the window refCon
-
- struct DocumentRecord
- {
- WindowRef owner; // the window
- ScrollBarPair scrollBars; // its scroll bars
- WEReference we; // its WASTE instance
- Handle fileAlias; // alias to associated file
- }; // DocumentRec
-
- typedef struct DocumentRecord DocumentRecord, *DocumentPtr, **DocumentHandle;
-
-
- /*
- * The external declaration of some global variables.
- */
-
- // These are defined in WEDemoIntf.c
-
- extern Boolean gHasColorQD; // true if Color QuickDraw is available
- extern Boolean gHasDragAndDrop; // true if Drag Manager is available
- extern Boolean gHasTextServices; // true is the Text Services Manager is available
- extern Boolean gExiting; // set this variable to drop out of the event loop and quit
-
- // These are defined in WEDemoEvents.c
-
- extern unsigned long gSleepTime; // sleep time for WaitNextEvent
- extern RgnHandle gMouseRgn; // mouse region for WaitNextEvent
-
- /*
- * Function Prototypes
- */
-
- // From DialogUtils.c
-
- pascal Boolean MyStandardDialogFilter( DialogRef, EventRecord *, short * );
- pascal ModalFilterUPP GetMyStandardDialogFilter( void );
- short GetDialogItemType( DialogRef, short );
- Handle GetDialogItemHandle( DialogRef, short );
- void GetDialogItemRect( DialogRef, short, Rect * );
- pascal void SetDialogItemProc( DialogRef, short, UserItemUPP );
-
- // From LongControls.c
-
- OSErr LCAttach( ControlRef );
- void LCDetach( ControlRef );
- void LCSetValue( ControlRef, long );
- void LCSetMin( ControlRef, long );
- void LCSetMax( ControlRef, long );
- long LCGetValue( ControlRef );
- long LCGetMin( ControlRef );
- long LCGetMax( ControlRef );
- void LCSynch( ControlRef );
-
-
- // From WEDemoIntf.c
-
- DocumentHandle GetWindowDocument(WindowRef);
- #if __cplusplus
- inline WEReference GetWindowWE(WindowRef window) { return (* GetWindowDocument(window))->we; }
- #else
- #define GetWindowWE(window) (* GetWindowDocument(window))->we
- #endif
- void ErrorAlert( OSErr );
- void ForgetHandle( Handle * );
- void ForgetResource( Handle * );
- OSErr NewHandleTemp( Size, Handle * );
- void PStringCopy( ConstStr255Param, Str255 );
-
- // From WEDemoAbout.c
-
- OSErr WETextBox( short, const Rect *, short );
- void DoAboutBox( short );
-
- // From WEDemoDrags.c
-
- pascal OSErr MyTrackingHandler( DragTrackingMessage, WindowRef, void *, DragReference );
- pascal OSErr MyReceiveHandler( WindowRef, void *, DragReference );
-
-
- // From WEDemoEvents.c
-
- void AdjustCursor( Point, RgnHandle );
- void DoMouseDown( const EventRecord * );
- void DoKeyDown( const EventRecord * );
- void DoDiskEvent( const EventRecord * );
- void DoOSEvent( const EventRecord * );
- void DoHighLevelEvent( const EventRecord * );
- void DoNullEvent( const EventRecord * );
- void DoWindowEvent( const EventRecord *);
- void ProcessEvent( void );
- OSErr GotRequiredParams( const AppleEvent * );
- OSErr InitializeEvents( void );
-
- // from WEDemoFiles.c
-
- OSErr ReadTextFile( const FSSpec *, WEReference );
- OSErr WriteTextFile( const FSSpec *, WEReference );
- pascal OSErr TranslateDrag( DragReference, ItemReference, FlavorType, Handle );
- pascal OSErr CheckObjectLock( short, long, StringPtr );
- pascal OSErr FSpCheckObjectLock( const FSSpec * );
-
- // from WEDemoInit.c
-
- OSErr Initialize( void );
- void Finalize( void );
-
- // from WEDemoMenus.c
-
- void SetDefaultDirectory( const FSSpec * );
- pascal Boolean MySFDialogFilter( DialogRef, EventRecord *, short *, void * );
- pascal ModalFilterYDUPP GetMySFDialogFilter( void );
- short FindMenuItemText( MenuRef, ConstStr255Param );
- Boolean EqualColor( const RGBColor *, const RGBColor * );
- void PrepareMenus( void );
- void DoDeskAcc( short );
- OSErr DoNew( void );
- OSErr DoOpen( void );
- OSErr SaveWindow( const FSSpec *, WindowRef );
- OSErr DoSaveAs( const FSSpec *, WindowRef );
- OSErr DoSave( WindowRef );
- OSErr DoClose( ClosingOption, SavingOption, WindowRef );
- OSErr DoQuit( SavingOption );
- void DoAppleChoice( short );
- void DoFileChoice( short );
- void DoEditChoice( short );
- void DoFontChoice( short );
- void DoSizeChoice( short );
- void DoStyleChoice( short );
- void DoColorChoice( short );
- void DoAlignChoice( short );
- void DoFeatureChoice( short );
- void DoMenuChoice( long );
- OSErr InitializeMenus( void );
-
- // from WEDemoScripting.c
-
- OSErr WEGetContentsDesc( long, long, Boolean, AEDesc *, WEReference );
- OSErr WESetContentsDesc( long, long, const AEDesc *, WEReference );
- OSErr InstallCoreHandlers( void );
-
- // from WEDemoWindows.c
-
- void DoDrag( Point, WindowRef );
- void DoGrow( Point, WindowRef );
- void DoZoom( short, WindowRef );
- Boolean DoContent( Point, const EventRecord *, WindowRef );
- void DoKey( char, const EventRecord * );
- void DoUpdate( WindowRef );
- void DoActivate( Boolean, WindowRef );
- OSErr CreateWindow( const FSSpec * );
- void DestroyWindow( WindowRef );
- void Resize( Point, WindowRef );
-
-
- #endif /* __WEDEMOAPP__ */